<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>PoC for BOI API EIC</title>

    <script src="../api/js/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="../api/boi.js"></script>

    <script type="text/javascript">
        //var BOI = parent.BOI;
        //var BOILib = parent.BOILib;
        var report = undefined;
        var flashvars = window.location.href.indexOf('?') > (-1) ? window.location.href.substr(window.location.href.indexOf('?') + 1) : "";

        BOI.Flash = {
            getSwf : function getSwf(report)
            {
                var swfTemplate = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+
                        'codebase="http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" '+
                        'WIDTH="100%" HEIGHT="100%" id="' + report.id + '">'+
                        '<PARAM NAME=FlashVars VALUE="' + flashvars + '">'+
                        '<PARAM NAME="movie" VALUE="' + report.url + '"> '+
                        '<param name="wmode" value="opaque" />' +
                        '<PARAM NAME="quality" VALUE="high">'+
                        '<PARAM NAME="bgcolor" VALUE="#FFFFFF">'+
                        '<PARAM NAME="play" VALUE="true">'+
                        '<PARAM NAME="loop" VALUE="true">'+
                        '<PARAM NAME=bgcolor VALUE="#FFFFFF">'+
                        '<EMBED src="' + report.url +'" quality=high bgcolor=#FFFFFF WIDTH="100%" HEIGHT="100%" '+
                        'NAME="' + report.id + '" ALIGN="" TYPE="application/x-shockwave-flash" wmode="opaque" '+
                        'play="true" loop="true" '+
                        'FlashVars="' + flashvars + '" '+
                        'PLUGINSPAGE="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'+
                        '</EMBED>'+
                        '</OBJECT>';
                return swfTemplate;
            },
            getMovie: function getMovie(movieName)
            {
                var movie = undefined;
                if (navigator.appName.indexOf("Microsoft") != -1) {
                    movie = document.getElementById(movieName);
                } else {
                    movie = document[movieName];
                }
                return movie;
            },
            sendEIC: function sendEIC(report, varname, value)
            {
                BOI.Flash.getMovie(report.id).setDataSource(varname, value);
            },
            initMovieBindings: function(report) {

                // Available Xcelsius External Interface calls:
                //                        movie.describeDataSources():XML
                //                        movie.getDataSource(rangeName:String):Object
                //                        movie.setDataSource(rangeName:String, newValue:Object):void
                //                        movie.addDataSourceChangeEventListener(rangeName:String, handlerFunctionName:String, sendCurrentValue:Boolean):void
                //                        movie.removeDataSourceChangeEventListener(rangeName:String, handlerFunctionName:String):void

                // Call the "rangeChangeHandler" callback handler when the range values change.
                var sendCurrentValue = true;  // false (do not pass current value), true (pass current value via callback).

                for(var i in report.variables)
                    getMovie(report.id).addDataSourceChangeEventListener(report.variables[i].name, "rangeChangeHandler", sendCurrentValue);
            }

        };

        function setSWFIsReady(movieName)
        {
            BOI.Flash.initMovieBindings(BOI.context.reports[movieName]);
        }

        function rangeChangeHandler(movieName, rangeName)
        {
            // Get the new range value.
            var newValue = getMovie(movieName).getDataSource(rangeName);
            BOI.Events.raiseEvent(BOI.Events.rangechange,[rangeName, newValue]);
            //alert(newValue);
        }

        var report;
        $(function(){
            report = BOI.createReport("MYREPORT", BOILib.ReportTypes.XcelsiusLocal);
            report.url = "../swf/sample_eic_flash_vars.swf";
            BOI.createContextVariable('url1','33333333333','string', BOILib.SelectionTypes.Single, report);

            var swf = BOI.Flash.getSwf(report);
            $('#content').html(swf);

            BOI.Events.addListener(BOI.Events.rangechange,function(args){
              //  alert("Event rangechange Caught for EIC " + args[0] + " = " + args[1]);
                 BOI.BOILib.Util.log('Event rangechange Caught for EIC ' + args[0] + ' = ' + args[1],true);
            });
        });
    </script>
</head>

<body>
    <input type="button" onclick="BOI.Flash.sendEIC(report, 'url1','999999999')" value="Refresh" />
    <div id="content"></div>
</body>
</html>